<?php

class Template_Documents_Manager extends Owl_Master_Template {
    protected function init() {
        $user = Owl_User::get_instance();
        if (!$user->is_logged_in()) {
            Owl_Functions::go_to_template("login");
        }
        assign("title", get_option("site_name") . " - " . __("Documents manager"));
        assign("page-title", __("Documents manager"));
        enqueue_style('default-setting,default-icon,default-ajax,default-jtable');
        enqueue_script('default-documents-manager');

        $this->owl_course = new Owl_Course();
        $this->all_courses = $this->owl_course->get_all_courses();
        if (empty($_GET["var"])) {
            $this->current_course = $this->all_courses[0];
        }
        else {
            $this->current_course = $this->owl_course->get_course($_GET["var"]);
            if ($this->current_course == false) {
                $this->current_course = $this->get_all_courses[0];
            }
        }
        
    }

    protected function main_content() {
?>
<div id="setting-navigation">
    <?php Owl_Default_Content::setting_navigation(); ?>
    <div style="clear:both;"></div>
</div>
<div id="setting-page-header" class="has-icon icon-documents-manager-48">
    <div id="setting-page-title">
        <?php put("page-title"); ?>
    </div>
</div>
<div id="setting-main-content">
    <h3><?php echo __("Courses"); ?></h3>
    <div id="courses-manager">
        <div style="padding: 10px 0px;">
            <?php $this->owl_course->print_course_dropdown($this->current_course["nice_url"]); ?>
            <a href="#" rel="course-add-container" class="form-toggle info-extra add"><span><?php echo __("Add course") ?></span></a>
            <a href="#" rel="course-edit-container" class="form-toggle info-extra edit"><span><?php echo __("Edit") ?></span></a>
            <a href="#" class="course-delete info-extra delete"><span><?php echo __("Delete") ?></span></a>
            <img src=" <?php Owl_Link::image_url(); ?>default/ajax-load.gif" class="ajax-load" alt="Ajax load" />
            <?php Owl_Default_Content::print_ajax_feedback(false); ?>
        </div>
        <div class="form-container hidden to-toggle" id="course-add-container">
            <?php echo $this->owl_course->build_form(); ?>
        </div>
        <div id="course-edit-container" class="to-toggle" style="display:none;">
            <?php echo $this->owl_course->build_form($this->current_course, 0, false); ?>
        </div>
    </div>
    <h3><?php echo __("Documents"); ?></h3>
    <div id="documents-manager">
        <table class="jtable" id="documents-table" border="0" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th width="50%">
                        <?php echo __("Document's name"); ?>
                    </th>
                    <th>
                        <?php echo __("Document's type"); ?>
                    </th>
                    <th>
                        <?php echo __("Download link"); ?>
                    </th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <td colspan="3" class="document-control">
                        <a href="#" rel="document-add-container" class="form-toggle info-extra add"><span><?php echo __("Add") ?></span></a>
                        <a href="#" class="document-delete info-extra delete"><span><?php echo __("Delete") ?></span></a>
                        <img src=" <?php Owl_Link::image_url(); ?>default/ajax-load.gif" class="ajax-load" alt="Ajax load" />
                    </td>
                </tr>
            </tfoot>
            <tbody>
            </tbody>
        </table>
        <div class="ajax-feedback document-delete-feedback">
            <div class="ajax-message">
                
            </div>
        </div>
        <div class="form-container hidden to-toggle" id="document-add-container">
            <?php $this->owl_course->print_document_form($this->current_course["nice_url"]); ?>
        </div>
    </div>
</div>
<?php
    }

}
